﻿@{
    ViewBag.Title = "RegulatoryForm";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<!--jqgrid表格组件start-->
<link href="~/Content/scripts/plugins/jqgrid/jqgrid.css" rel="stylesheet" />
<script src="~/Content/scripts/plugins/jqgrid/grid.locale-cn.js"></script>
<script src="~/Content/scripts/plugins/jqgrid/jqgrid.min.js"></script>
<!--表格组件end-->
<script>
    var organizeId = request('organizeId');
    var TypeId = request('TypeId');
    var _Category = request('Category');
    var _ItemId = request('ItemId');
    var _rowid = 1;
    $(function () {
        GetGrid();
        GetGrid1();
    });

    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var queryJson = new Object();
        queryJson["organizeId"] = organizeId;
        queryJson["TypeId"] = TypeId;
        queryJson["Category"] = _Category;
        queryJson["ItemId"] = _ItemId;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "/DailyEventManage/OpenShop/GetShopItemList",
            postData: queryJson,
            datatype: "json",
            height: $(window).height() - 141.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", index: "Id", hidden: true },
                { label: "编号", name: "Code", index: "Code", width: 70, align: "center" },
                { label: "名称", name: "Name", index: "Name", width: 100, align: "center" },
                { label: "工作阶段", name: "CategoryId", index: "CategoryId", width: 100, align: "center" },
                { label: "责任部门", name: "ResponDepts", index: "ResponDepts", width: 70, align: "center" }
            ],
            rownumbers: true,
            rowNum: 1000,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            },
            ondblClickRow: function (rowid, iRow, iCol, e) {
                var obj = $("#" + this.id).getRowData(rowid);
                $('#gridTable1').addRowData(_rowid, obj);
                $('#gridTable').delRowData(rowid);
                _rowid++;
            }
        });
    }

    //加载表格
    function GetGrid1() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable1');
        $gridTable.jqGrid({
            datatype: "json",
            height: $(window).height() - 141.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", index: "Id", hidden: true },
                { label: "编号", name: "Code", index: "Code", width: 70, align: "center" },
                { label: "名称", name: "Name", index: "Name", width: 100, align: "center" },
                { label: "工作阶段", name: "CategoryId", index: "CategoryId", width: 100, align: "center" },
                { label: "责任部门", name: "ResponDepts", index: "ResponDepts", width: 70, align: "center" }
            ],
            viewrecords: true,
            rownumbers: true,
            shrinkToFit: false,
            hidegrid: false,
            unwritten: false,
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
    }

    function TopMost() {
        var id = $('#gridTable1').jqGrid('getGridParam', 'selrow');
        if (checkedRow(id)) {
            $("#gridTable1 tr td.sgexpanded").trigger("click");
            var $tr = $('#gridTable1 tr#' + id);
            if ($tr.index() != 1)
                $tr.prevAll("tr:last").after($tr);
            $tr.getGridParam('selrow');
        }
    }

    function SortUp() {
        var id = $('#gridTable1').jqGrid('getGridParam', 'selrow');
        if (checkedRow(id)) {
            $("#gridTable1 tr td.sgexpanded").trigger("click");
            var $tr = $('#gridTable1 tr#' + id);
            if ($tr.index() != 1)
                $tr.prev().before($tr);
            $tr.getGridParam('selrow');
        }
    }


    function SortDown() {
        var id = $('#gridTable1').jqGrid('getGridParam', 'selrow');
        if (checkedRow(id)) {
            $("#gridTable1 tr td.sgexpanded").trigger("click");
            var $tr = $('#gridTable1 tr#' + id);
            $tr.next().after($tr);
            $tr.getGridParam('selrow');
        }
    }

    function DownMost() {
        var id = $('#gridTable1').jqGrid('getGridParam', 'selrow');
        if (checkedRow(id)) {
            $("#gridTable1 tr td.sgexpanded").trigger("click");
            var $tr = $('#gridTable1 tr#' + id);
            $tr.nextAll("tr:last").after($tr);
            $tr.getGridParam('selrow');
        }
    }

    //保存表单
    function AcceptClick() {
        if (!$('#form1').Validform()) {
            return false;
        }
        var $gridTable = top.frames["Form1"].$("#gridTable1");
        var obj = $("#gridTable1").jqGrid("getRowData");
        for (var i = 0; i < obj.length; i++) {
            obj[i].MItemId = obj[i].Id;
            obj[i].TypeId = TypeId;
            delete obj[i].Id;
        }
        $gridTable[0].addJSONData(obj);
        //$.each(obj, function (index, data) {
        //    $gridTable.addRowData(_rowid, data);
        //    _rowid++;
        //});
        dialogMsg("操作成功。", 1);
        dialogClose();
    }
</script>
<div id="SelectType" style="margin-top: 20px; margin-right: 30px;">
    <table class="form">
        <tr>
            <th class="formTitle" colspan="2" style="padding-top: 10px; padding-left: 30px;">
                <div style="width:80%;float:left;"><table id="gridTable"></table></div>
                <div style="width: 20%; float: right; text-align: center; line-height:338px;height:338px;"><i class="fa fa-exchange"></i></div>
            </th>
            <th class="formTitle" colspan="2" style="padding-top:10px;">
                <div style="width:90%;float:left;">
                    <table id="gridTable1"></table>
                </div>
                <div style="width: 10%; float: right;">
                    <a class="btn btn-default" onclick="TopMost();"><i class="fa fa-arrow-up"></i>最上</a><br />
                    <a class="btn btn-default" onclick="SortUp();"><i class="fa fa-arrow-up"></i>向上</a><br />
                    <a class="btn btn-default" onclick="SortDown();"><i class="fa fa-arrow-down"></i>向下</a><br />
                    <a class="btn btn-default" onclick="DownMost();"><i class="fa fa-arrow-down"></i>最下</a><br />
                </div>
            </th>
        </tr>
    </table>
</div>